﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Path.Question;

namespace Path.Answer
{
    public class Bob: IPath
    {
        public string GetRelativePath(string currentPath, string targetPath)
        {
            string[] current = currentPath.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries);
            string[] target = targetPath.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries);

            int i = 0;

            for (; i < current.Length; i++)
            {
                if (i >= target.Length || current[i] != target[i])
                {
                    break;
                }
            }

            StringBuilder sb = new StringBuilder();
            for (int j = i; j < current.Length; j++)
            {
                sb.Append("../");
            }
            for (int k = i; k < target.Length; k++)
            {
                sb.Append(target[k] + "/");
            }
            sb.Remove(sb.Length - 1, 1);


            return sb.ToString();
        }
    }
}
